import unittest
def subNm(N,M,i,j):
    mask = 0
    for id in xrange(i,j):
        mask+=(1<<id)
    mask = (mask^0xffff)
    N = (N & mask) 
    M = M <<i
    N = N | M
    return N


class TestSubNum(unittest.TestCase):
    inputs = (
              (16,7,0,3,23),
              (15,7,0,3,15),
              (0,7,1,4,14),
              (0,1,1,2,2)
              )
    def testBasic(self):
        for N,M,i,k,res in self.inputs:
            self.assertEqual(subNm(N,M,i,k,),res)
            
def numBitsChange(N,M):
    "5.5"
    changes =  N^M
    count=0
    while changes>0:
        if 1&changes>0:
            count+=1
        changes=changes>>1
    return count
        
class TestNNumBitsChange(unittest.TestCase):
    inputs= (
             (15,7,1),
             (8,7,4),
             (2,3,1)
             )
    
    def testInputs(self):
        for N,M,res in self.inputs:
            self.assertEqual(numBitsChange(N, M), res)
            
            
